package com.yin.myproject.netty.chapter06;

import java.io.*;

/**
 * @author Eason
 * @create 2017-12-27 22:27
 **/
public class SerializableStudent {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Student st = new Student("Tom",'M',20,3.6);
        File file = new File("D:/chpter06");
        file.createNewFile();
        //Student对象序列化过程
        FileOutputStream fos = new FileOutputStream(file);
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(st);
        oos.flush();
        oos.close();
        fos.close();

        //Student对象反序列化过程
        FileInputStream fis = new FileInputStream(file);
        ObjectInputStream ois = new ObjectInputStream(fis);
        Student st1 = (Student) ois.readObject();
        System.out.println("name = " + st1.getName());
        System.out.println("sex = " + st1.getSex());
        System.out.println("year = " + st1.getYear());
        System.out.println("gpa = " + st1.getGpa());
        ois.close();
        fis.close();
    }
}
